package com.first.nell.components.keyboard

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.RelativeLayout
import androidx.fragment.app.FragmentManager
import com.first.nell.R
import com.first.nell.base.BaseFormAction
import com.first.nell.databinding.ViewFirstNellNumberKeyboardBinding

class NumberKeyboard : RelativeLayout, BaseFormAction {

    lateinit var mFirstNellViewFirstNellBinding: ViewFirstNellNumberKeyboardBinding
    private lateinit var vFirstNellRootFirstNellView: View

    private var mFirstNellSupportFirstNellFragmentFirstNellManager: FragmentManager? = null

    private var mFirstNellOnFirstNellActionFirstNellClickFirstNellListener: (Int) -> Unit = {}

    constructor(context: Context?) : this(context, null)
    constructor(context: Context?, attrs: AttributeSet?) : this(context, attrs, 0)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : this(
        context,
        attrs,
        defStyleAttr,
        0
    )

    @SuppressLint("Recycle")
    constructor(
        context: Context?,
        attrs: AttributeSet?,
        defStyleAttr: Int,
        defStyleRes: Int,
    ) : super(
        context,
        attrs,
        defStyleAttr,
        defStyleRes
    ) {
        context?.let {
            vFirstNellRootFirstNellView = View.inflate(it, R.layout.view_first_nell_number_keyboard, this)
            mFirstNellViewFirstNellBinding = ViewFirstNellNumberKeyboardBinding.bind(vFirstNellRootFirstNellView)
            initFirstNellSubviews()
        }
    }

    override fun initFirstNellSubviews() {
        try {
            mFirstNellViewFirstNellBinding.textKeyboardNum0.setOnClickListener {
                mFirstNellOnFirstNellActionFirstNellClickFirstNellListener.invoke(0)
            }

            mFirstNellViewFirstNellBinding.textKeyboardNum1.setOnClickListener {
                mFirstNellOnFirstNellActionFirstNellClickFirstNellListener.invoke(1)
            }

            mFirstNellViewFirstNellBinding.textKeyboardNum2.setOnClickListener {
                mFirstNellOnFirstNellActionFirstNellClickFirstNellListener.invoke(2)
            }

            mFirstNellViewFirstNellBinding.textKeyboardNum3.setOnClickListener {
                mFirstNellOnFirstNellActionFirstNellClickFirstNellListener.invoke(3)
            }

            mFirstNellViewFirstNellBinding.textKeyboardNum4.setOnClickListener {
                mFirstNellOnFirstNellActionFirstNellClickFirstNellListener.invoke(4)
            }

            mFirstNellViewFirstNellBinding.textKeyboardNum5.setOnClickListener {
                mFirstNellOnFirstNellActionFirstNellClickFirstNellListener.invoke(5)
            }

            mFirstNellViewFirstNellBinding.textKeyboardNum6.setOnClickListener {
                mFirstNellOnFirstNellActionFirstNellClickFirstNellListener.invoke(6)
            }

            mFirstNellViewFirstNellBinding.textKeyboardNum7.setOnClickListener {
                mFirstNellOnFirstNellActionFirstNellClickFirstNellListener.invoke(7)
            }

            mFirstNellViewFirstNellBinding.textKeyboardNum8.setOnClickListener {
                mFirstNellOnFirstNellActionFirstNellClickFirstNellListener.invoke(8)
            }

            mFirstNellViewFirstNellBinding.textKeyboardNum9.setOnClickListener {
                mFirstNellOnFirstNellActionFirstNellClickFirstNellListener.invoke(9)
            }

            mFirstNellViewFirstNellBinding.imageKeyboardDel.setOnClickListener {
                mFirstNellOnFirstNellActionFirstNellClickFirstNellListener.invoke(-1)
            }

            mFirstNellViewFirstNellBinding.imageKeyboardDismiss.setOnClickListener {
                mFirstNellOnFirstNellActionFirstNellClickFirstNellListener.invoke(-2)
            }
        } catch (e: java.lang.Exception) {
            e.printStackTrace()
        }
    }

    override fun setFirstNellFragmentFirstNellManager(manager: FragmentManager) {
        mFirstNellSupportFirstNellFragmentFirstNellManager = manager
    }

    override fun setFirstNellOnFirstNellActionFirstNellClickFirstNellListener(listener: (Int) -> Unit) {
        mFirstNellOnFirstNellActionFirstNellClickFirstNellListener = listener
    }

    override fun setFirstNellTitle(title: String) {

    }

    override fun setFirstNellDetail(detail: String) {

    }

    override fun setFirstNellContent(content: String) {

    }

    override fun setFirstNellHint(hint: String) {

    }

    override fun setFirstNellDetailFirstNellColor(detailColor: Int) {

    }

    override fun setFirstNellTitleFirstNellColor(titleColor: Int) {

    }
}